<script type="text/javascript" charset="utf-8">
$(document).ready(function() {
	var organisationId = getURLParameter("organisationId");
	var smTable = $('#supporting-material-table')
	.dataTable(
			{
				"sDom" : 'rtp',
				"sPaginationType" : "bootstrap",
				"iDisplayLength" : 15,
				"bServerSide" : true,
				"bPaginate" : true,
				"sAjaxSource" : "supportingMaterialTableAjax.action",
				"aoSearchCols": [
	 				null,
	 				null,
	 				null,
	 				null,
	 				null,
	 				{"sSearch": "Yes"}
	 			],
				"aoColumnDefs" : [ {
					"fnRender" : function(o, val) {
						if (o.aData[5] == "Yes") {
							return '<a href=editSupportingMaterial.action?organisationId=' + organisationId + '&supportingMaterialId=' + o.aData[6] + '>' + o.aData[0] + '</a>';													
						} else {
							return '<a href="#" onClick=toActiveSupportingMaterial(' + o.aData[6] + ',' + organisationId + ')>' + o.aData[0] + '</a>';
						}
					},
					"aTargets" : [0]
				} ],
				"fnServerParams": function ( aoData ) {
			  		aoData.push( { "name": "organisationId", "value": organisationId});
				}
			});	
	
	$('#check-active-supporting-material').click(function() {
		var other = $('#check-active-supporting-material:checked').val();
		if (other != undefined) {
			smTable.fnFilter("", 5, true, false);
		} else {
			smTable.fnFilter("Yes", 5, true, false);
		}
	});	
});

function toActiveSupportingMaterial(materialId, organisationId) {
	var r = confirm('Do you want to make this Supporting Material active?');
	if (r == true) {		
		window.location.replace("activeSupportingMaterial.action?organisationId=" + organisationId + "&supportingMaterialId=" + materialId);
	}
}
</script>
<div class="tab-pane" id="4">
	<div class="row-fluid">
		<div class="span12">
			<div class="">
				<h5>Current List of Supporting Materials</h5>
			</div>
			<div id="supporting-material" class="box-content">
				<form action="#" class='form-horizontal' method="post">
					<div class="control-group">
						<div id="inactive-div">
							<a href="addSupportingMaterial.action?organisationId=<s:property value='organisationId' />" class="btn btn-success">Create</a>
							<label class="checkbox"><input type="checkbox"
								name="check-inactive" id="check-active-supporting-material"> Include
								In-active</label>
						</div>
						<table id="supporting-material-table"
							class="table table-striped table-bordered">
							<thead>
								<tr>
									<th>URL</th>
									<th>Description</th>
									<th>Type</th>
									<th>Added By</th>
									<th>Added Date</th>
									<th>Is Active?</th>
								</tr>
							</thead>
							<tbody>
							</tbody>
						</table>
					</div>
				</form>
			</div>
		</div>
	</div>
</div>